// import { Page } from "@/types/storeModule"
import { assign } from 'lodash-es'

const state = {
  // 接口调用参数
  params: {
    page: {
      currentPage: 1,
      pageSize: 20,
      totalCount: 0,
      totalPage: 0,
      sortField: 'rank_order',
      order: 'asc'
    },
    options: {}
  },
  roles: {}, // 权限
  apiName: 'rank',
  privileges: [
    'admin-rank-add',
    'admin-rank-edit',
    'admin-rank-download-import-tmpl',
    'admin-rank-export',
    'admin-rank-import'
  ],
  // 列表data数据
  isLoading: false,
  tableData: [],
  searchData: [
    {
      id: 'entity.rankNameCn',
      name: '榜单名称',
      type: 'text',
      hint: '榜单名称',
      defaultValue: ''
    },
    {
      id: 'entity.rankYear',
      name: '榜单年度',
      type: 'date_range',
      hint: '榜单年度',
      defaultValue: ''
    },
    {
      id: 'entity.rankType',
      name: '榜单类型',
      type: 'select',
      hint: '榜单类型',
      options: [
        {
          key: '1',
          value: '实体榜单'
        },
        {
          key: '2',
          value: '人物榜单'
        }
      ]
    }
  ],
  tableHeadList: [
    {
      label: '榜单名称',
      prop: 'rankNameCn',
      width: 220
    },
    {
      label: '序号',
      prop: 'rankOrder',
      width: 40
    },
    {
      label: '榜单年度',
      prop: 'rankYear',
      width: 60
    },
    {
      label: '榜单类型',
      prop: 'rankType',
      width: 60,
      slotName: 'rankType'
    },
    {
      label: '上榜机构数',
      prop: 'rankType',
      width: 80
    },
    {
      label: '排名数',
      prop: 'qnEmail',
      width: 60
    },
    {
      label: '最佳机构奖项',
      prop: 'qnTel',
      width: 100
    },
    {
      label: '投资家奖项',
      prop: 'qnUtime',
      width: 100
    },
    {
      label: '最佳投资家奖项',
      prop: 'qnUtime',
      width: 100
    }
  ],
  // 导入模板编码，由后台提供，value => md5(‘上榜机构明细导入表’)
  importTemplateCode: '021e8d75f647826137d82a629c9804e6'
}

// getters
const getters = {}

// actions
const actions = {}

// mutations
const mutations = {
  // 更新页面搜索内容
  updateSearchData(state, payload: any[]) {
    state.searchData = payload
  },
  // 更新表格 loading 状态
  updateLoading(state, payload: boolean) {
    state.isLoading = payload
  },

  // 更新数据page
  updatePage(state, payload: any) {
    state.params.page = assign(state.params.page, payload)
  },

  // 更新数据Condition
  updateCondition(state, payload: any) {
    state.params.condition = cloneDeep(payload)
  },

  // 更新data数据
  updateTableData(state, payload: any[]) {
    state.tableData = payload
  },
  // 更新列表表头数据
  updateEditTableList(state, payload: any[]) {
    state.tableHeadList = payload
  },
  // 更新列表参数数据
  updateParams(state, payload: any) {
    state.params = Object.assign({}, state.params, payload)
  },
  // 更新权限
  updateRoles(state, payload: Record<string, boolean>) {
    state.roles = payload
  }
}

export default {
  namespaced: true,
  state,
  getters,
  actions,
  mutations
}
